<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="./css/animate.css">
    <script src="js/vue.js"></script>
</head>

<body>
    <div id="app">
        <h3>父组件</h3>
        <input type="button" value="显示组件A" @click=" name='CompA' ">
        <input type="button" value="显示组件B" @click=" name='CompB' ">
        <transition
            enter-active-class="animated fadeInRight"
            leave-active-class="animated fadeOutLeft"
        >
            <component :is="name"></component>
        </transition>
    </div>
    <template id="tempa">
        <div style="background-color: rosybrown;">
            <h3>组件A</h3>
        </div>
    </template>
    <template id="tempb">
        <div style="background-color: sandybrown;">
            <h3>组件B</h3>
        </div>
    </template>
</body>
<script>
    new Vue({
        el: '#app',
        data: {
            name:"CompA"
        },
        components: {
            CompA: {
                template: "#tempa"
            },
            CompB: {
                template: "#tempb"
            }
        }
    });
</script>

</html>